﻿using System;
using System.Globalization;

namespace LeanEngine.Extensions
{
    /// <summary>
    /// Extension methods for the data type System.Char.
    /// </summary>
    public static class CharExtensions
    {
        #region Parse Default Culture

        /// <summary>
        /// Convert to System.Int16 according to the number format of culture set in the thread.
        /// </summary>        
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.FormatException"></exception>
        /// <exception cref="System.OverflowException"></exception>
        /// <param name="value">The value to be converted.</param>
        public static Int16 ToInt16(this char value)
        {
            return Int16.Parse(value.ToString(), CultureInfo.CurrentCulture.NumberFormat);
        }

        /// <summary>
        /// Convert to System.Int32 according to the number format of culture set in the thread.
        /// </summary>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.FormatException"></exception>
        /// <exception cref="System.OverflowException"></exception>
        /// <param name="value">The value to be converted.</param>
        public static Int32 ToInt32(this char value)
        {
            return Int32.Parse(value.ToString(), CultureInfo.CurrentCulture.NumberFormat);
        }

        /// <summary>
        /// Convert to System.Int64 according to the number format of culture set in the thread.
        /// </summary>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.FormatException"></exception>
        /// <exception cref="System.OverflowException"></exception>
        /// <param name="value">The value to be converted.</param>
        public static Int64 ToInt64(this char value)
        {
            return Int64.Parse(value.ToString(), CultureInfo.CurrentCulture.NumberFormat);
        }

        #endregion

        #region Parse Custom Culture

        /// <summary>
        /// Convert to System.Int16 according to the formatting information supplied.
        /// </summary>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.FormatException"></exception>
        /// <exception cref="System.OverflowException"></exception>
        /// <param name="value">The value to be converted.</param>
        /// <param name="culture">An System.IFormatProvider that supplies culture-specific formatting information about s.</param>
        public static Int16 ToInt16(this char value, IFormatProvider culture)
        {
            return Int16.Parse(value.ToString(), culture);
        }

        /// <summary>
        /// Convert to System.Int32 according to the formatting information supplied.
        /// </summary>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.FormatException"></exception>
        /// <exception cref="System.OverflowException"></exception>
        /// <param name="value">The value to be converted.</param>
        /// <param name="culture">An System.IFormatProvider that supplies culture-specific formatting information about s.</param>
        public static Int32 ToInt32(this char value, IFormatProvider culture)
        {
            return Int32.Parse(value.ToString(), culture);
        }

        /// <summary>
        /// Convert to System.Int64 according to the formatting information supplied.
        /// </summary>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.FormatException"></exception>
        /// <exception cref="System.OverflowException"></exception>
        /// <param name="value">The value to be converted.</param>
        /// <param name="culture">An System.IFormatProvider that supplies culture-specific formatting information about s.</param>
        public static Int64 ToInt64(this char value, IFormatProvider culture)
        {
            return Int64.Parse(value.ToString(), culture);
        }

        #endregion
    }
}
